﻿namespace Web.Control.WWW.Group
{
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Text.RegularExpressions;
    using System.IO;
    using Lx.Web.Common.ControlsUI;
    using Lx.Web.Common.UI;
    using Model.WWW_WWW.Group;
    using BLF.WWW_WWW.Group;
    using System.Collections.Generic;
    using BLF;

    public class Taggroup : BaseControl
    {
        
        /// <summary>
        /// Tag名
        /// </summary>
        protected string Tags = "";
        /// <summary>
        /// 页面
        /// </summary>
        protected int pageIndex = 1;
        /// <summary>
        /// 目标语言
        /// </summary>
        protected string Learn = "";
        protected string memberno = "";
        /// <summary>
        /// 组的类型
        /// </summary>
        protected string gtype = "0";
        protected Repeater repGroup;
        protected Repeater repTopic;
        protected Repeater rptLL;
        /// <summary>
        /// 数据数量
        /// 
        /// </summary>
        protected int RecordCount = 0;
        protected string sortField = "1";
        protected List<TopicModel> tmList;
        protected List<GroupModel> gmList;
        ArrayList al = new ArrayList();
        protected Literal lLCount;
        /// <summary>
        /// 登陆人名称
        /// </summary>
        protected string NickName = "";
        protected override void OnLoad(EventArgs e)
        {
            int l = 15;
            if (lLCount != null) int.TryParse(lLCount.Text, out l);
            if ( !string.IsNullOrEmpty(Request["tag"])&& Request["tag"] != "")
            {
                Tags = Request["tag"].Replace("?", "").Replace("/", "").Replace("-", "").Replace("&", "");
                if (Request.Cookies["italkiLearn"] == null && Request.Cookies["italkiSpeak"] == null)
                {
                    HttpCookie llCookie = new HttpCookie("italkiLearn", "all");
                    HttpCookie blCookie = new HttpCookie("italkiSpeak", "all");
                    Response.Cookies.Add(llCookie);
                    Response.Cookies.Add(blCookie);
                }
                if (!string.IsNullOrEmpty(Request["p"]))
                {
                    if (Request["p"] == "L")
                    {
                        pageIndex = 999;
                    }
                    else
                    {
                        int.TryParse(Request["p"], out pageIndex);
                    }
                }
                if (!string.IsNullOrEmpty(Request["ll"]) && Request["ll"] != "")
                {
                    Learn = Request["ll"];
                    HttpCookie llCookie = new HttpCookie("italkiLearn", Learn);
                    Response.Cookies.Add(llCookie);
                    if (Request.Cookies["italkiSpeak"] == null)
                    {
                        HttpCookie blCookie = new HttpCookie("italkiSpeak", "all");
                        Response.Cookies.Add(blCookie);
                    }


                }
                else
                {
                    Learn = Request.Cookies["italkiLearn"].Value;
                }
                if (!string.IsNullOrEmpty(Request["gtype"]))
                {
                    gtype = Request["gtype"];
                }
                if (!string.IsNullOrEmpty(Request["st"]))
                {
                    sortField = Request["st"];
                }
                if (HttpContext.Current.User.Identity.Name != "")
                {
                    memberno = HttpContext.Current.User.Identity.Name;
                }
                    al = BLF.WWW_WWW.Group.Group.GetTagGroups(memberno, Tags, Learn == "all" ? "" : Learn, gtype == "0" ? "" : gtype, sortField, pageIndex, l);
                gmList = al[0] as List<GroupModel>;
                RecordCount = al[1] == null ? 0 : (int)al[1];
                tmList = al[2] as List<TopicModel>;
                NickName = al[3].ToString();
                if (rptLL != null)
                {
                    List<LanguageObj> lanObjList = new List<LanguageObj>();
                    lanObjList.AddRange(BLF.StaticData.GetPopLanguageList);
                    rptLL.DataSource = lanObjList;
                    rptLL.DataBind();
                }
                if (repGroup != null)
                {
                    repGroup.DataSource = gmList;
                    repGroup.DataBind();
                }
                if (repTopic != null)
                {
                    repTopic.DataSource = tmList;
                    repTopic.DataBind();
                }
                //标题
                this.DynamicTitle = GetText("GP555", new string[] { Tags });
                this.DynamicKeywords = GetText("GP556", new string[] { Tags });
                this.DynamicDescription = GetText("GP557", new string[] { Tags });
                base.OnLoad(e);
            }
            else {
                Response.End();
                return;
            }

        }
        
       
    }
}

